package com.weed.table.Column;

import java.awt.Color;
import java.awt.Font;
import java.text.Format;
import javax.swing.table.*;
import javax.swing.DefaultCellEditor;
import javax.swing.JTextField;

/**
 * <p>Title: JRSwing</p>
 * <p>Description: 列扩展</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author Jason
 * @version 1.0
 */

public class TableColumnEx
    extends TableColumn {

  protected TableCellEditor headerEditor;
  protected boolean isHeaderEditable;

  public TableColumnEx() {

    setHeaderEditor(createDefaultHeaderEditor());
    isHeaderEditable = true;
  }

  public TableColumnEx(int modelIndex) {
    super(modelIndex);
    setHeaderEditor(createDefaultHeaderEditor());
    isHeaderEditable = true;
  }

  public void setHeaderEditor(TableCellEditor headerEditor) {
    this.headerEditor = headerEditor;
  }

  public TableCellEditor getHeaderEditor() {
    return headerEditor;
  }

  public void setHeaderEditable(boolean isEditable) {
    isHeaderEditable = isEditable;
  }

  public boolean isHeaderEditable() {
    return isHeaderEditable;
  }

  public void copyValues(TableColumn base) {
    modelIndex = base.getModelIndex();
    identifier = base.getIdentifier();
    width = base.getWidth();
    minWidth = base.getMinWidth();
    setPreferredWidth(base.getPreferredWidth());
    maxWidth = base.getMaxWidth();
    headerRenderer = base.getHeaderRenderer();
    headerValue = base.getHeaderValue();
    cellRenderer = base.getCellRenderer();
    cellEditor = base.getCellEditor();
    isResizable = base.getResizable();
  }

  protected TableCellEditor createDefaultHeaderEditor() {
    return new DefaultCellEditor(new JTextField());
  }
  
    public int getDataType()
    {
        return dataType;
    }

    public Format getFormat()
    {
        return format;
    }

    public int getHorizontalAlignment()
    {
        return horizontalAlignment;
    }

    public Color getForeground()
    {
        return foreground;
    }

    public Font getFont()
    {
        return font;
    }

    public int getWidth()
    {
        if(visible)
            return super.getWidth();
        else
            return 0;
    }

    public int getPreferredWidth()
    {
        if(visible)
            return super.getPreferredWidth();
        else
            return 0;
    }

    public String getRendererStyle()
    {
        return rendererStyle;
    }

    public String getEditorStyle()
    {
        return editorStyle;
    }

    public int getLength()
    {
        return length;
    }

    public int getScaleLength()
    {
        return scaleLength;
    }

    public boolean isVisible()
    {
        return visible;
    }

    public void setDataType(int type)
    {
        dataType = type;
    }

    public void setFormat(Format format)
    {
        this.format = format;
    }

    public void setHorizontalAlignment(int alignment)
    {
        horizontalAlignment = alignment;
    }

    public void setForeground(Color color)
    {
        foreground = color;
    }

    public void setFont(Font font)
    {
        this.font = font;
    }

    public void setLength(int length)
    {
        this.length = length;
    }

    public void setRendererStyle(String style)
    {
        rendererStyle = style;
    }

    public void setEditorStyle(String style)
    {
        editorStyle = style;
    }

    public void setScaleLength(int length)
    {
        scaleLength = length;
    }

    public void setVisible(boolean visible)
    {
        this.visible = visible;
    }

    protected Color foreground;
    protected Font font;
    protected int dataType;
    protected int horizontalAlignment;
    protected boolean isMultLines;
    protected Format format;
    protected int length;
    protected int scaleLength;
    protected String rendererStyle;
    protected String editorStyle;
    protected boolean visible = true;
}